define(function(require){
	var $=require("jq");
	var productId=$("#recommendList").attr("data-productId");
	if(!/\d+/.test(productId)){
		return ;
	}
	$.post("/product_recomendList.do?rand="+Math.random(),{productId:productId},function(json){
		var lis=[];
		var rems=json;
		for(var i=0,l=rems.length;i<l;i++){
			var rem=rems[i];
			var li={
				tag:"li",
				children:[
				{
					tag:"div",
					"class":"p-img",
					children:{
						tag:"a",
						href:"/product/"+rem.articleId+".html",
						children:{
							tag:"img",
							src:rem.picPath||"",
							alt:"",
							data_img:rem.picPath||"",
							onerror:"this.src='/pinzhiV2.0/images/replace150.jpg'",
							width:150,
							height:150
						}
					}
				},
				{
					tag:"div",
					"class":"p-name",
					children:{
						tag:"a",
						href:"/product/"+rem.articleId+".html",
						title:"",
						children:rem.articleTitle
					}
				},
				{
					tag:"div",
					"class":"p-price fcff3",
					children:"¥"+rem.price
				}
				]
				          
			};
			if(i==l-1){
				li["class"]="no-br";
			}
			lis.push(li);
		}
		var h2={tag:"h2",children:"热门推荐"};
		var conf=[
		          	h2,
		          	{
		          		tag:"div",
		          		"class":"con-l-box-goods",
		          		children:[
		          		    {
		          		    	tag:"ul",
		          		    	children:lis
		          		    },
		          		    {
		          		    	tag:"div",
		          		    	"class":"clearfix"
		          		    }
		          		]
		          	}
		          ];
		html=createHTML(conf);
		$("#recommendList").html(html);
	},"json");
	
	function createHTML(conf){
		var html="";
		if(conf.constructor == {}.constructor){
			html =html+ "<"+conf.tag;
			for(var attr in conf){
				if(attr=="tag"||attr=="children"){
					continue;
				}
				html =html+" "+attr+"=\""+conf[attr]+"\"";
			}
			html=html+">";
			var children = conf.children||[];
//			if( children.constructor=={}.constructor){
//				html=html+createHTML(children);
//			}else{
//				for(var i=0,l=children.length;i<l;i++){
//					html=html+createHTML(children[i]);
//				}
//			}
			html=html+createHTML(children);
			html=html+"</"+conf.tag+">";
		}else if(typeof conf == "string"){
			return conf;
		}else if(conf.constructor==[].constructor){
			for(var i=0,l=conf.length;i<l;i++){
				html=html+createHTML(conf[i]);
			}
		}
		return html;
	}
});